package com.znsb.msfq.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.TextView;

import com.znsb.msfq.R;
import com.znsb.msfq.view.PickerView;

import java.util.ArrayList;


//个人信息
public class PersionDialog {
    private static PickerView pickerView1;
    private static TextView close, ensure;
    private static Dialog dialog;

    public static void getinit(Activity context,final ArrayList<String> list, final TextView textView,
                               String default_areaname) {
        // 选项2
        dialog = new Dialog(context, R.style.CustomProgressDialog);
        dialog.setContentView(R.layout.dialog_persion);
        pickerView1 = (PickerView) dialog.findViewById(R.id.time_select_1);
        close = (TextView) dialog.findViewById(R.id.close);
        ensure = (TextView) dialog.findViewById(R.id.ensure);
        // morende
        pickerView1.setData(list);
        dialog.getWindow().setGravity(Gravity.BOTTOM);
        dialog.show();
        dialog.setCanceledOnTouchOutside(true);// 设置点击屏幕Dialog消失
        // 设置全屏
        WindowManager windowManager = context.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = (int) (display.getWidth()); //设置宽度
        dialog.getWindow().setAttributes(lp);
        // 设置默认
        if (!TextUtils.isEmpty(default_areaname)) {

            for (int i = 0; i < list.size(); i++) {
                if (default_areaname.equals(list.get(i))) {
                    pickerView1.setSelected(i);
                }
            }
        }

        close.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
//                dialog.dismiss();
                dialog.cancel();
                dialog=null;
            }
        });
        ensure.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                textView.setText(list.get(pickerView1.getSelected()));
                dialog.dismiss();
                dialog.cancel();
                dialog=null;
            }
        });
    }

}
